recvmsg: compute cmsg nexthdr end without firsthdr#1583
Conversation
In io_uring_recvmsg_cmsg_nexthdr() the cmsg region end is computed as io_uring_recvmsg_cmsg_firsthdr(o, msgh) + o->controllen. firsthdr returns NULL when o->controllen < sizeof(struct cmsghdr), and the addition becomes a non-zero offset applied to a null pointer, which is undefined behavior. Compute end directly as name + namelen + controllen so the arithmetic is always on a real pointer. The value is identical to the old expression when firsthdr would have succeeded, and the function still returns NULL for any cmsg that does not fit in the cmsg region. Signed-off-by: rootvector2 <dxbnaveed.k@gmail.com>
|
Just curious, did you actually hit a crash with this in the production, or was it flagged by ubsan/a static analyzer? |
|
not a production crash, it was flagged by static analysis. when |
|
When can |
|
in the documented so it's really a cleanup: dropping the redundant |
Noticed io_uring_recvmsg_cmsg_nexthdr() computes the cmsg region end as
io_uring_recvmsg_cmsg_firsthdr(o, msgh) + o->controllen. firsthdr
returns NULL when o->controllen < sizeof(struct cmsghdr), so this
becomes a non-zero offset applied to a null pointer, which is undefined
behavior. Compute end directly as name + namelen + controllen so the
arithmetic is always on a real pointer; the value matches the old
expression when firsthdr would have succeeded.